//-----------------------------------------------------------------------
// <copyright file="MultiInterfaceFactoryTest.cs" company="NMock2">
//
//   http://www.sourceforge.net/projects/NMock2
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// </copyright>
// This is the easiest way to ignore StyleCop rules on this file, even if we shouldn't use this tag:
// <auto-generated />
//-----------------------------------------------------------------------
namespace NMock2.Test.Monitoring
{
    using System;
    using NUnit.Framework;
    using NMock2.Monitoring;

    public interface A { }
    public interface B {}
    public interface C {}
    public interface A_B {}

    [TestFixture]
    public class MultiInterfaceFactoryTest
    {
        MultiInterfaceFactory factory;

        [SetUp]
        public void SetUp()
        {
            factory = new MultiInterfaceFactory("TestedMultiInterfaceFactory");
        }
        
        [Test]
        public void CreatesTypeInfoObjectsThatRepresentAnInterfaceThatExtendsAllParameterInterfaces()
        {
            Type newType = factory.GetType(typeof(A),typeof(B),typeof(C));

            Assert.IsTrue( typeof(A).IsAssignableFrom(newType), "new type is an A");
            Assert.IsTrue( typeof(B).IsAssignableFrom(newType), "new type is an B");
            Assert.IsTrue( typeof(C).IsAssignableFrom(newType), "new type is an C");
        }

        [Test]
        public void ReturnsTheSameTypeWhenPassedTheSameArguments()
        {
            Type type = factory.GetType(typeof(A),typeof(B));
            Type sameType = factory.GetType(typeof(A),typeof(B));
            Type otherType = factory.GetType(typeof(A),typeof(C));

            Assert.IsTrue( type == sameType, "should be same type");
            Assert.IsTrue( type != otherType, "should be different type");
        }

        [Test]
        public void ReturnsTheSameTypeWhenPassedTheSameArgumentsInDifferentOrder()
        {
            Type type = factory.GetType(typeof(A),typeof(B));
            Type sameType = factory.GetType(typeof(B),typeof(A));
            
            Assert.IsTrue( type == sameType, "should be same type");
        }

        [Test]
        public void AvoidsNameClash()
        {
            Type type = factory.GetType(typeof(A), typeof(B), typeof(C));
            Type otherType = factory.GetType(typeof(A_B), typeof(C));

            Assert.IsTrue(type != otherType, "types should be different");
        }
    }
}
